#!/usr/bin/make -f


ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
INSTALL_PROGRAM += -s
endif

build: build-stamp
build-stamp:
	dh_testdir
	./autogen.sh
	$(MAKE) prefix=/usr
	touch build-stamp

# this is really not part of debian package build, but just for convinience

clean: checkroot
	$(checkdir)
	make superclean
	rm -f build-stamp
	dh_clean

# Build architecture-independent files here.
binary-indep: build
# We have nothing to do by default.

# Build architecture-dependent files here.
install: build
	dh_testdir
	dh_testroot
	dh_installdirs
	$(MAKE) prefix="$(CURDIR)/debian/scratchbox2/usr" install
	# make lintian happy
	rm -f debian/scratchbox2/usr/share/scratchbox2/host_usr
	ln -sf ../.. debian/scratchbox2/usr/share/scratchbox2/host_usr
	mv debian/scratchbox2/usr/lib* debian/libsb2/usr/

binary-arch: install
	dh_testdir -a
	dh_testroot -a
	dh_installdocs -a README docs/SB2_internals_1st_ed_20120425.pdf
	dh_installchangelogs -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	# FIXME, do in postinst
	dh_installdeb -a
	dh_shlibdeps -Llibsb2 -l/usr/lib/libsb2
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-arch

.PHONY: build clean binary-indep binary-arch binary checkroot prebuild

define checkdir
	dh_testdir
endef

checkroot:
	$(checkdir)
	dh_testroot
